package io.esirong.base;

import android.app.Application;
import android.content.Context;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.multidex.MultiDex;
import io.esirong.ActivityManager;

/**
 * @author 黄嵘才(HuangRc)
 */
public class BaseApplication extends Application {
    /**
     * 全局唯一的context
     */
    private volatile static BaseApplication application;

    /* # 添加兼容矢量图无法从资源ID解析到的错误*/
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        application = this;
        //MultiDex分包方法 必须最先初始化
        MultiDex.install(this);
    }

    /**
     * 获取全局唯一上下文
     *
     * @return BaseApplication
     */
    public static BaseApplication getApplication() {
        return application;
    }

    /**
     * 退出应用
     */
    public void exitApp() {
        try {
            ActivityManager.INSTANCE.finishAll();
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(0);
        } catch (Exception e) {
            //ignore
        }
    }
}
